#Include SchiffKarte.DEF

#Include CARDUTIL.DEF
#Include COLOURS.DEF

Call WaitForCard()
ResetCard : Call CheckSW1SW2()

Private Name$ : Call GetApplicationID (Name$) : Call CheckSW1SW2()
If Name$ <> ApplicationName$ Then Print "This is not a SchiffKarte!" : Exit

Private PassName$, Func$
Private SNumber$ As Integer
Private Challenge As Long

Call GetRandom(Challenge)
Challenge = Challenge / 13 + 100
Call GetRRights(Challenge)

Select Case SW1SW2
   Case SWRLocked: 
      FgCol = BrightRed : Print "Reading locked!"
   Case Else : 
      Call CheckSW1SW2()
      FgCol = BrightGreen : Print "Read rights granted"
End Select

Call GetRandom(Challenge)
Challenge = Challenge / 11 + 100
Call GetWRights(Challenge)

Select Case SW1SW2
   Case SWWLocked: 
      FgCol = BrightRed : Print "Writing locked!"
   Case Else : 
      Call CheckSW1SW2()
      FgCol = BrightGreen : Print "Write rights granted"
End Select

FgCol = BrightCyan : Print "Function Codes:"
FgCol = BrightCyan : Print "0: Exit"
FgCol = BrightCyan : Print "2: Get Name"
FgCol = BrightCyan : Print "3: Reset Card"
FgCol = BrightCyan : Print "4: Get SerialNumber"

Do
   FgCol = BrightCyan : Print "Enter Function Code:"
   FgCol = BrightYellow : Line Input Func$
   
   If Func$ = "0" Then 
      REM FgCol = BrightYellow : Print "Exit"
      Exit
   End If
   
   If Func$ = "2" Then
      REM FgCol = BrightYellow : Print "Get Name"
      Call GetName(PassName$)
      Select Case SW1SW2
         Case swNotPersonalised : 
            FgCol = BrightRed : Print "Card not personalised!"
         Case Else : 
            Call CheckSW1SW2()
            FgCol = BrightGreen : Print PassName$
      End Select
   End If
   
   If Func$ = "3" Then
      REM FgCol = BrightYellow : Print "Reset Card"
      Call ResetPersonalisedCard() : Call CheckSW1SW2()
      FgCol = BrightGreen : Print "OK"
   End If
   
   If Func$ = "4" Then      
      Call GetSerialNumber(SNumber$) : Call CheckSW1SW2()
      FgCol = BrightGreen : Print SNumber$
   End If
   
   FgCol = BrightCyan : Print ""
Loop

